package org.example.back.service.Forum;


import org.example.back.entity.Forum.ForumPostLike;
import org.example.back.mapper.Forum.ForumPostLikeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ForumPostLikeService {
    @Autowired
    private ForumPostLikeMapper likeMapper;

    public boolean toggleLike(Long postId, int userId) {
        ForumPostLike like = new ForumPostLike();
        like.setPostId(postId);
        like.setUserId(userId);
        if (likeMapper.existsLike(like)) {
            likeMapper.deleteLike(like);
            return false; // 取消点赞
        } else {
            likeMapper.insertLike(like);
            return true; // 点赞成功
        }
    }

    public int getLikeCount(Long postId) {
        return likeMapper.countLikesByPostId(postId);
    }
}

